今天要學習如何使用 CSS 創建一個背景漸變動畫效果,為網站增添動感和視覺吸引力
<div class="gradient-background">Hello, World!</div>
body 背景動畫將背景漸變效果應用到 body 元素上
body {
    margin: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(45deg, #ff0066, #ffcc00, #66ffcc, #00ccff);
    background-size: 400% 400%;
    animation: gradientAnimation 5s ease infinite;
}
background: linear-gradient(45deg, #ff0066, #ffcc00, #66ffcc, #00ccff):background-size: 400% 400% : 設置背景漸變的尺寸,為了在動畫過程中能夠覆蓋整個元素animation: gradientAnimation 5s ease infinite : 應用動畫效果,5 秒鐘循環一次,使用平滑的過渡效果.gradient-background 的大小、顏色.gradient-background{
    font-size: 4rem;
    color: white;
}
keyframes 動畫需要定義一個關鍵幀動畫 gradientAnimation,實現背景顏色的平滑過渡
@keyframes gradientAnimation {
    0% {
        background-position: 0% 0%;
    }
    50% {
        background-position: 100% 100%;
    }
    100% {
        background-position: 0% 0%;
    }
}
